#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    getchar();

    while (n--)
    {
        char pitch1[10], pitch2[10];
        scanf("%s %s", pitch1, pitch2);
        getchar();

        int degree, half;
        int sum_half[10] = { 0,2,4,5,7,9,11,12 };
        int x1, x2, y1, y2;

        switch (pitch1[0])
        {
        case 'C': x1 = 0; break;
        case 'D': x1 = 1; break;
        case 'E': x1 = 2; break;
        case 'F': x1 = 3; break;
        case 'G': x1 = 4; break;
        case 'A': x1 = 5; break;
        case 'B': x1 = 6; break;
        }
        y1 = pitch1[1] - '0';

        switch (pitch2[0])
        {
        case 'C': x2 = 0; break;
        case 'D': x2 = 1; break;
        case 'E': x2 = 2; break;
        case 'F': x2 = 3; break;
        case 'G': x2 = 4; break;
        case 'A': x2 = 5; break;
        case 'B': x2 = 6; break;
        }
        y2 = pitch2[1] - '0';

        degree = y2 * 7 + x2 - (y1 * 7 + x1) + 1;
        half = y2 * 12 + sum_half[x2] - (y1 * 12 + sum_half[x1]);
        printf("%d %d\n", degree, half);
    }
    return 0;
}